<template>
  <el-dialog :visible="isshowassignrole" title="角色权限管理" @close="Esc">
    <el-checkbox-group v-model="checkList">
      <el-checkbox v-for="role in roleList" :key="role.id" :label="role.id">
        {{ role.name }}
      </el-checkbox>
    </el-checkbox-group>
    <template #footer>
      <el-row type="flex" justify="center">
        <el-button @click="Esc">取 消</el-button>
        <el-button type="primary" @click="setthisrole">确 定</el-button>
      </el-row>
    </template>
  </el-dialog>
</template>

<script>
import { get_All_role } from '@/api/role'
import { Getemployeeinformation } from '@/api/user'
import { assignRoles } from '@/api/employees'
export default {
  props: {
    isshowassignrole: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      checkList: [],
      roleList: [],
      userid: ''
    }
  },
  created() {
    this.get_All_role()
  },
  methods: {
    async GetcheckList(id) {
      this.userid = id
      const { roleIds } = await Getemployeeinformation(id)
      this.checkList = roleIds
    },
    async get_All_role() {
      const { rows } = await get_All_role()
      this.roleList = rows
    },
    Esc() {
      this.$emit('update:isshowassignrole', false)
    },
    async setthisrole() {
      await assignRoles({ id: this.userid, roleIds: this.checkList })
      this.$message.success('修改成功')
      this.Esc()
    }
  }
}
</script>

<style>

</style>
